package com.qfedu.aunt.commons.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qfedu.aunt.commons.exception.BusinessException;
import com.qfedu.aunt.commons.pojo.Store;
import com.qfedu.aunt.commons.mapper.StoreMapper;
import com.qfedu.aunt.commons.result.ResponseCode;
import com.qfedu.aunt.commons.service.StoreService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaobobo
 * @since 2022-10-27
 */
@Service
public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements StoreService {

    @Autowired
    private StoreMapper storeMapper;

    @Override
    public List<Store> findStoreByCityName(String cityName) throws Exception{
        if(StringUtils.isEmpty(cityName)){
           throw new BusinessException(ResponseCode.PARAMETER_ERROR.getCode(),
                   ResponseCode.PARAMETER_ERROR.getMessage());
        }
        //执行到这里说明参数没有问题
        //构建查询的条件
        QueryWrapper<Store> storeQueryWrapper = new QueryWrapper<>();
        storeQueryWrapper.eq("city_name",cityName);

        //接下来进行查询
        List<Store> stores = storeMapper.selectList(storeQueryWrapper);
        return stores;
    }
}
